/*
 * Copyright 2005-2015 shunwang.com. All Rights Reserved.
 */

package vashion.azeroth.api.result;

import java.io.Serializable;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.ObjectMapper;

public class Result<T> implements Serializable {

	private static final long serialVersionUID = 6193864707256948758L;

	@JsonIgnore
	private ObjectMapper mapper = new ObjectMapper();

	private Boolean isSuccesful = true;

	private int msgId = 0;

	private String msg = "成功";

	private T data;

	public Result() {

	}

	public Result(T data) {
		this.data = data;
	}

	public Result(int msgId) {
		this.msgId = msgId;
	}

	public Result(int msgId, String msg) {
		this.msgId = msgId;
		this.msg = msg;
	}

	public Result(Boolean succesful) {

		this.isSuccesful = succesful;
	}

	public int getMsgId() {
		return msgId;
	}

	public void setMsgId(int msgId) {
		this.msgId = msgId;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public Boolean getIsSuccesful() {
		return isSuccesful;
	}

	public void setIsSuccesful(Boolean isSuccesful) {
		this.isSuccesful = isSuccesful;
	}

	public String toJSON() {
		try {
			return mapper.writeValueAsString(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
